﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ExaminationSys.DataAccess.Entity
{
    public enum LoginType
    {
        登录=1,
        已登录栏目=2,
        最后测试条目=3
    }

    public enum EnumSectionType : uint
    {
        学习栏目 = 1,
        外链接 = 2,
        下载板块 = 3,
        信息栏目 = 4

    }

    public enum EnumTestType
    {
        动机测试=1,
        水平测试=2
    }

    public enum EnumLevel
    {
        初级=1,
        中级=2,
        高级=3
    }

    public enum  EnumNodeType
    {
        知识点=1,
        文件夹=2
    }

    public enum EnumEnumSubSectionType
    {
        文章 = 1,
        测试 = 2,
        练习=3
    }

    public enum EnumCommentType
    {
        按分数 = 1,
        按时间 = 2
    }


    public class SectionTypeItem
    {
        public int SectionTypeId { get; set; }
        public string subTypeItemTitle { get; set; }
        public int subTypeItem { get; set; }
        public string Icon { get; set; }
        public SectionTypeItem()
        {
        }
        public static List<SectionTypeItem> GetSectionTypeItem()
        {
            List<SectionTypeItem> items = new List<SectionTypeItem>();

            //i 指的是EnumSectionType 中的枚举
            for (int i = 1; i < 5; i++)
            {
                if (i == 1)
                {
                    items.Add(new SectionTypeItem() { SectionTypeId = i, subTypeItemTitle = "子栏目管理", subTypeItem = 0, Icon = "../../resources/images/icon.png"});
                    items.Add(new SectionTypeItem() { SectionTypeId = i, subTypeItemTitle = "动机测试", subTypeItem = 1, Icon = "../../resources/images/icon.png" });
                    items.Add(new SectionTypeItem() { SectionTypeId = i, subTypeItemTitle = "水平测试", subTypeItem = 2, Icon = "../../resources/images/icon.png" });
                }
                if (i == 2)
                {
                    items.Add(new SectionTypeItem() { SectionTypeId = i, subTypeItemTitle = "编辑链接", subTypeItem = 0, Icon = "../../resources/images/icon.png" });
                }
                if (i == 3)
                {
                    items.Add(new SectionTypeItem() { SectionTypeId = i, subTypeItemTitle = "管理", subTypeItem = 0, Icon = "../../resources/images/icon.png" });

                }
                if (i == 4)
                {
                    items.Add(new SectionTypeItem() { SectionTypeId = i, subTypeItemTitle = "编辑", subTypeItem = 0, Icon = "../../resources/images/icon.png" });
                }
            }

            return items;

        }
    }

    public class CommonEnum
    {
        /// <summary>
        /// 将枚举转换成ArrayList
        /// </summary>
        /// <returns></returns>
        public static Dictionary<int, string> EnumToDictionary(Type enumType)
        {
            Dictionary<int, string> dic = new Dictionary<int, string>();
            var members =  Enum.GetValues(enumType);
            foreach (var i in Enum.GetValues(enumType))
            {
                string name = Enum.GetName(enumType, i);
                if (typeof(EnumSectionType) == enumType)
                {
                    EnumSectionType key = (EnumSectionType)Enum.Parse(enumType, name, true);
                    dic.Add((int)key, name);
                }

                if (typeof(EnumTestType) == enumType)
                {
                    EnumTestType key = (EnumTestType)Enum.Parse(enumType, name, true);
                    dic.Add((int)key, name);
                }
              
 

            }
             
            return dic;
        }

        public static int GetKeyBy(string Name,Type enumType)
        {
       
            foreach (var i in Enum.GetValues(enumType))
            {
                string name = Enum.GetName(enumType, i);
                if (typeof(EnumSectionType) == enumType)
                {
                    EnumSectionType key = (EnumSectionType)Enum.Parse(enumType, name, true);
                    if (Name == name)
                        return (int)key;
                   
                }

                if (typeof(EnumTestType) == enumType)
                {
                    EnumSectionType key = (EnumSectionType)Enum.Parse(enumType, name, true);
                    if (Name == name)
                        return (int)key;
                }



            }

            return -1;
        }
    }
}
